<html>
	<head>
		<script src="../gears_init.js"></script>
		<script src="../GearsORM.js"></script>
		<script src="../GearsORM.Events.js"></script>
		<script src="../GearsORM.ResultIterator.js"></script>
		<script src="../GearsORM.Sql.js"></script>
		<script src="../GearsORM.Fields.js"></script>
		<script src="../GearsORM.Model.js"></script>
		<script src="../GearsORM.Introspection.js"></script>
		<script src="../GearsORM.Transaction.js"></script>
		<script>
			GearsORM.dbName = "test.selfRelation";
			var TreeNode = new GearsORM.Model({
				name:"TreeNode",
				fields:
				{
					data:new GearsORM.Fields.String({maxLength:25}),
					parent:new GearsORM.Fields.OneToMany({related:"TreeNode",allowNull:true}),
					childs:new GearsORM.Fields.ManyToOne({related:"TreeNode"})
				}
			});
			var Tests =
			{
				up:function()
				{
					TreeNode.dropTable();
					TreeNode.createTable();
				},
				"test that create with null and inner relation works":function()
				{
					var root = new TreeNode({data:"i am the root",parent:null}).save();
					var node1 = new TreeNode({data:"i am node 1",parent:root}).save();
					var node2 = new TreeNode({data:"i am node 2",parent:root}).save();
				},
				"test that select works":function()
				{
					UnitTest.assertEqual(2,new TreeNode(1).childs.select().toArray().length);
				},
				"test that remove works":function()
				{
					var root = new TreeNode(1);
					root.childs.remove();
					UnitTest.assertEqual(0,root.childs.select().toArray().length);
				},
				down:function()
				{
					TreeNode.dropTable();
				}
			};
		</script>
		<script src="unit_test.js"></script>
	</head>
	<body>
		
	</body>
</html>